package com.ytzl.itripsearch.service.impl;

import com.ytzl.itripsearch.service.HotCityHotelService;
import com.ytzl.vo.ItripHotCityHotelVo;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.List;

@Service
public class HotCityHotelServiceImpl implements HotCityHotelService {

    @Autowired
    private SolrClient solrClient;

    @Override
    public List<ItripHotCityHotelVo> queryHotelCityList(Integer cityId,Integer count) throws SolrServerException, IOException {
        //构造solr的查询条件对象
        SolrQuery query=new SolrQuery("*:*");
        //设置查询条件
        query.setFilterQueries("cityId:"+cityId);
        //设置分页
        query.setStart(0);
        query.setRows(count);
        //排序
        query.setSort("id", SolrQuery.ORDER.desc);
        //执行查询，获取查询结果
        QueryResponse response=solrClient.query(query);
        //将从solr查询到的数据转换为Java对象
        return response.getBeans(ItripHotCityHotelVo.class);
    }
}
